package com.pt.pok;

import com.pt.pok.model.PokerCommand;

/**
 * @author Roman.Ivanov@playtech.com
 * @date 1/23/12
 *       <p/>
 *       This interface specifies general protocol converter which is able to handle protocol messages and
 *       serialize domain model objects to protocol specific format
 *       <p/>
 *       P - protocol formatted message data
 */
public interface ProtocolConverter<P> {

    /**
     * Converts domain command to protocol formatted data
     * 
     * @param command domain command
     * @return protocol formatted data
     */
    P convertToProtocolCommand(PokerCommand command);

    /**
     * Converts protocol formatted data to domain object
     * 
     * @param classId class id {@link com.pt.pok.model.ClassIds}
     * @param protocolCommand protocol specific formatted data
     * @return domain object
     * @throws GeneralProxyException in case of any troubles
     */
    PokerCommand convertFromProtocolCommand(int classId, P protocolCommand)
        throws GeneralProxyException;

    /**
     * Receives protocol formatted data and its classId
     * 
     * @param classId class id {@link com.pt.pok.model.ClassIds}
     * @param protocolMessage protocol formatted message data
     * @throws GeneralProxyException in case of any problem
     */
    void handleCommand(int classId, P protocolMessage)
        throws GeneralProxyException;

    /**
     * Add command listener
     * 
     * @param commandListener where library client implements its code for specific message event
     */
    void addCommandListener(CommandListener commandListener);

    /**
     * Remove command listener
     * 
     * @param commandListener remove
     */
    void removeCommandListener(CommandListener commandListener);

}
